package com.ktjiaoyu.controller;

import com.ktjiaoyu.entity.SysUser;
import com.ktjiaoyu.service.SysUserService;
import com.ktjiaoyu.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author Jane
 * @date 2024-12-26 11:47
 */
@Controller
@RequestMapping("/api/user")
public class UserController extends BaseController{

    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/login")
    public String login(Model model
                        , @RequestParam(value = "account",required = true) String account
                        , @RequestParam(value = "password",required = true) String password
    ){
        SysUser param = new SysUser();
        param.setAccount(account);
        param.setPassword(password);

        SysUser loginUser = sysUserService.findUser(param);
        if (loginUser!=null){
            super.session(Constants.SESSION_USER,loginUser);
            //return "index.jsp";
            return  super.redirect("main/index");
        }else{
            //model.addAttribute("msg","账密错误,登录失败");
            request(Constants.REQUEST_ERROR,"账密错误,登录失败");
            return super.forward("/login.jsp");//"login.jsp";
        }
    }
    @RequestMapping("/main/index")
    public String login(){
        return "index.jsp";
    }
}
